package org.ahuanlien.crm.service.impl;

import org.ahuanlien.crm.domain.Car;
import org.ahuanlien.crm.mapper.CarMapper;
import org.ahuanlien.crm.query.CarQueryObject;
import org.ahuanlien.crm.service.ICarService;
import org.ahuanlien.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

@Service
public class CarServiceImpl implements ICarService{
    @Autowired
    CarMapper carMapper;

    public int deleteByPrimaryKey(Long id) {
        return carMapper.deleteByPrimaryKey(id);
    }

    public int insert(Car record) {
        return carMapper.insert(record);
    }

    public Car selectByPrimaryKey(Long id) {
        return carMapper.selectByPrimaryKey(id);
    }

    public List<Car> selectAll() {
        return carMapper.selectAll();
    }

    public int updateByPrimaryKey(Car record) {
        return carMapper.updateByPrimaryKey(record);
    }

    public PageResult query(CarQueryObject qo) {
        int count = carMapper.queryForCount();
        List<Car> list = carMapper.queryForList(qo);
        if(count== 0){
            return new PageResult(0, Collections.EMPTY_LIST);
        }
        return new PageResult(count,list);
    }
}
